Array.prototype.reduce = function(fn,initVal) {
	// body...
	let prev;
	let index;
	if(initVal === undefined){
		prev = this[0];
		index = 1;
	}else{
		// 如果指定初始值
		prev = initVal;
		index = 0;
	}
	while(index < this.length){
		curr = this[index];
		prev = fn.call(null,prev,curr,index)
		index++;
	}
	return prev
};
var arr = [1,2,3]
let newArr = arr.reduce(function(a,b){
	return a+b
},0)
console.log(newArr)